package com.example.eurekaconsume;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

@Service
public class ConsumeService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "toError")
    public String index(){
        String resp=restTemplate.getForEntity("http://provide-service/provide/index",String.class).getBody();
        return resp;
    }

    /**
     * 這種方式不可用
     * @return
     */
    public String uri(){
        URI uri=URI.create("http://localhost:8888/provide/index");
        String resp=restTemplate.getForEntity(uri,String.class).getBody();
        return resp;
    }

    public String toError(){
        return "this is a error!";
    }
}
